<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>04_运算符</title>
</head>
<body>
<script>
    //如果比较运算符左右两边有数字会转为数字再进行比较
    console.log(3 > 2);//true
    console.log('3' > 2);//true
    console.log(3 > '2');//true
    console.log(Number('3'));//3
    //如果比较运算符左右两边都是字符串,会比较它们的编码值
    console.log('超' > '赞');
    console.log('3' > '10');//51>49 true
    /* '3'. charCodeAt()查看编码值*/
    console.log('3'.charCodeAt(0));//51
    console.log('10'.charCodeAt(0));//49

    //除法会直接显示实际运算结果
    console.log(3 / 2);//1.5

    let a = 1;
    let b = true;
    //松散比较运算符,只比较值, Number(true)=1
    console.log(a == b);//true
    //严格比较运算符，先比较类型,再比较值number != boolean
    console.log(a === b);//false

    //Number()将参数转换为数字，如果得不到数字结果,会得到NaN(Not a Number)
    console.log(Number(true),typeof Number(true));
    console.log(Number('3'),typeof Number('3'));
    console.log(Number('你好'),typeof Number('你好'));//NaN number

    //Boolean()将参数转换为布尔值
    //以下情况会转换为false: 0,NaN,undefined,null,空字符串''
    console.log(Boolean(0));//false
    console.log(Boolean(NaN));//false
    console.log(Boolean(undefined));//false
    console.log(Boolean(null));//false
    console.log(Boolean(''));//false
    console.log(Boolean('0'));//true
    console.log(Boolean(' '));//true
    console.log(Boolean('下午好'));//true

    let c = 0;
    //三元运算符
    console.log(c==0 ? 'YES' : 'NO');//YES
    //=是赋值符号,给c赋值为, Boolean(0)=faLse,所以取N0
    console.log(c=0 ? 'YES' : 'NO');//NO
</script>
</body>
</html>